package com.dy.树与二叉树.二叉树.链式存储;

public class 衍生算法 {
    //查找算法
    public static BiTreeNode searchNode(BiTreeNode T, Object x) {
        if (T != null) {
            if (T.data == x) {
                return T;
            }
            BiTreeNode tmp = searchNode(T.lchild, x);
            if (tmp == null) {
                return searchNode(T.rchild, x);
            } else return tmp;
        }
        return null;
    }

    //深度
    public static int getDepth(BiTreeNode t) {
        if (t != null) {
            int lDepth = getDepth(t.lchild);
            int rDepth = getDepth(t.rchild);
            return 1 + (lDepth > rDepth ? lDepth : rDepth);
        }
        return 0;
    }
}